<template>
  <!-- <div>封堵白名单</div> -->
  <a-row>
    <a-col>
      <a-card :bordered="false" style="margin-bottom: 10px">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form-model ref="ruleForm" :model="pageFilter" :label-col="labelCol" :wrapper-col="wrapperCol">
            <a-row style="display:flex">
              <a-col :span="6">
                <a-form-model-item label="涉诈网站">
                  <a-input placeholder="请输入任务名称" v-model="pageFilter.fraudUrl"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="6">
                <a-form-model-item label="诈骗类型" style="margin-left:0px">
                  <a-select v-model="pageFilter.fraudType" allowClear placeholder="请选择" style="width:100%;">
                    <a-select-option value="">全部</a-select-option>
                    <a-select-option v-for="(item, key) in fraud_typeArr" :key="key" :value="item.value">{{
                      item.title
                    }}
                    </a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :span="6">
                <a-form-model-item label="批次号" style="margin-left:0px">
                  <a-input placeholder="请输入任务名称" v-model="pageFilter.batchNo"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="6" style="margin-left:0px">
                <a-space :size="6">
                  <a-button type="primary" @click="onQuery" icon="search">查询</a-button>
                  <a-button @click="onResetForm" icon="reload">重置</a-button>
                </a-space>
              </a-col>
            </a-row>
            <a-col :span="6">
              <a-form-model-item label="反馈状态">
                <a-select style="width:100%" v-model="pageFilter.feedbackStatus">
                  <a-select-option v-for="(item, key) in feedbackStatus" :key="key" :value="item.value">{{
                      item.title
                    }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="反馈时间">
                <a-range-picker v-model="pageFilter.aaa"/>
              </a-form-model-item>
            </a-col>
          </a-form-model>
        </div>
      </a-card>
      <a-card :bordered="false">
        <div>

          <a-button type="primary" @click="onExport" style="margin-right:10px">导出</a-button>
          <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="true" :loading="loading"
            :columns="columns" :dataSource="pageData" @selectedRowKey="onSelectedRow" @change="onTableChange">
            <template slot="fraudType" slot-scope="text, record">
                <span>{{ fraud_typeArr[record.fraudType-1]?fraud_typeArr[record.fraudType-1].text:'' }}</span>
            </template>
          </z-table>
        </div>

      </a-card>
    </a-col>
  </a-row>
</template>

<script>
import { downLoadMix } from '@/utils/export-util/util'
import { getDictItemsFromCache } from '@/api/api'
import { pageBlockingFeedbackLog,exportBlockingFeedbackLog } from '@/api/plugging/Police'
export default {
  mounted () {
    this.onQuery()
  },
  data() {
    return {
      idsDTO:{
        ids:[]
      },
      feedbackStatus:[
        {
          title:'失败',
          value:0
        },
        {
          title:'成功',
          value:1
        },
      ],
      labelCol: { span: 5 },
      wrapperCol: { span: 16 },
      loading: false,
      pageFilter: {
        pageNo: 1,
        pageSize: 10,
      },
      pageData: {
        records: [
          {
            realName: "111"
          }
        ]
      },
      fraud_typeArr: getDictItemsFromCache('case_fraud_type'),
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          width: 60,
          align: 'center',
          customRender: (text, record, index) =>
            `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
        },
        {
          title: '数据编号',
          dataIndex: 'dataNo',
          align: 'center',
        },
        {
          title: '涉诈网站',
          dataIndex: 'fraudUrl',
          align: 'center',
        },
        {
          title: '涉诈类型',
          dataIndex: 'fraudType',
          align: 'center',
          scopedSlots: { customRender: 'fraudType' },
        },
        {
          title: '发现时间',
          dataIndex: 'discoveryTime',
          align: 'center',
        },
        {
          title: '反馈时间',
          dataIndex: 'feedbackTime',
          align: 'center',
        },
        {
          title: '反馈状态',
          dataIndex: 'feedbackStatus',
          align: 'center',
          customRender:text => `${text == 1?'成功':'失败'}`
        },
        {
          title: '失败原因',
          dataIndex: 'failReason',
          align: 'center',
        },
        {
          title: '批次号',
          dataIndex: 'batchNo',
          align: 'center',
        },

      ]
    }
  },
  methods: {
    onExport(){
      exportBlockingFeedbackLog(this.idsDTO).then(
        async res => {
            if(res && res.size>0) {
              const fileName = '封堵反馈日志.xls'
              await downLoadMix(res, fileName)
            } else {
              this.$message.warn("导出失败！")
            }
      })
        .catch((e) => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    NewSubmission() {
      this.$router.push({
        path: '/plugging/police/InvolvingFraud/NewSubmission',
        query: {}
      })
    },
    // aa(){
    //   this.$router.push({
    //   path: '/plugging/police/InvolvingFraud/EditSubmission',
    //   query: {}
    // })
    // },
    // bb(){
    //   this.$router.push({
    //   path: '/plugging/police/InvolvingFraud/ReportDetails',
    //   query: {}
    // })
    // },
    onQuery() {
      this.pageFilter.pageNo = 1
      this.refreshTable()
      console.log(this.pageData);
    },
    //重置
    onResetForm() {
      this.pageFilter = {
        pageNo: 1,
        pageSize: 10,
        departmentId: this.departmentId
      }
      this.refreshTable()
    },
    onSelectedRow(keys) {
      this.selectKeys = keys
      this.idsDTO.ids = keys
      console.log(this.idsDTO.ids);
      this.isDisabled = keys.length > 0 ? false : true
    },
    onTableChange(pagination, pageFilter, sorter) {
      let keyMap = { currentPage: 'pageNo' }
      let paginations = Object.keys(pagination).reduce((newData, key) => {
        let newKey = keyMap[key] || key
        newData[newKey] = pagination[key]
        return newData
      }, {})
      this.pageFilter = Object.assign({}, this.pageFilter, paginations)
      this.refreshTable()
    },
    refreshTable() {
        this.loading = true
        pageBlockingFeedbackLog(this.pageFilter).then( res => {
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
          } else {
            this.$message.success(res.message)
            this.loading = false
          }
        })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
      },
  }
}
</script>

<style lang="less" scoped>
.search-wrapper-btn {
  position: absolute;
  right: 8%;
  top: 22px;
  z-index: 100;
}
</style>